﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.Windows.Browser;
using Utility;
using Utility.Service;

namespace ProductList
{
    public partial class MainPage : UserControl
    {
        private string uploadpath;

        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            this.LayoutUpdated += new EventHandler(MainPage_LayoutUpdated);
            uploadpath = App.Current.Host.Source.AbsoluteUri.Substring(0, App.Current.Host.Source.AbsoluteUri.IndexOf("/ClientBin"));
        }

        void MainPage_LayoutUpdated(object sender, EventArgs e)
        {
            HtmlElement el = HtmlPage.Document.GetElementById("silverlightControlHost");
            el.SetStyleAttribute("height", "1800px");
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ServiceClient client = CUtility.GetServiceClient();
            client.ReadCommonBySortCompleted += new EventHandler<ReadCommonBySortCompletedEventArgs>(client_ReadCommonBySortCompleted);
            client.ReadCommonBySortAsync("2");
        }

        void client_ReadCommonBySortCompleted(object sender, ReadCommonBySortCompletedEventArgs e)
        {
            if (null == e.Error)
            {
                if (null != e.Result)
                {
                    BitmapImage bit = new BitmapImage(new Uri(uploadpath + "/" + e.Result[0].Content, UriKind.Absolute));
                    Image img = new Image();
                    img.Width = 1257;
                    img.Source = bit;
                    this.spContent.Children.Add(img);
                }
            }
            else
            {
                throw e.Error;
            }
        }
    }
}
